
#include <iostream>
#include <fstream>
#include "lklist.h"

using namespace std;

typedef int elemtype;
typedef lklisttpl<elemtype> lklist;

void delredundancy( lklist * );

int main()
{
    ifstream in("in.txt");
    vector<elemtype> v;
    lklist *h;
    int i, n;
    int t;

    in >> n;
    for ( i = 0; i < n; i++ ){
	in >> t;
	v.push_back(t);
    }

    h = createlk<lklist,elemtype>( v, WITHHEAD );
    printlk( h, WITHHEAD ); cout << endl;
    delredundancy( h );
    printlk( h, WITHHEAD ); cout << endl;
    destorylk( h, WITHHEAD );

    return 0;
}

/* ******************************************************
 *             Answer to this question.
 * ******************************************************/

void delredundancy( lklist *h )
{
    lklist *p, *q;
    
    p = h->next;
    while( p ){
        while( p->next && (p->next->data == p->data) ){
	    q = p->next;
            p->next = q->next;
            delete q;
        }
        p = p->next;
    }
    
    return;
}
